<?php
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group(['middleware' => 'login'], function () {

    /**
     * 所有功能模块
     */
    Route::get('index', 'Api\IndexController@index');
    $list = \App\Models\AuthRule::get()->toArray();
    foreach($list as $val) {
        $name = explode("_",$val["name"]);
        $href = str_replace('_', '/', $val['name']);
        if(count($name) ==1) continue;
        Route::any($href, 'Api\\'.$name[0].'Controller@'.$name[1].'');
    }
    /**
     * 自定义模块
     */
    $menus = \App\Http\Controllers\AuthController::$menus;
    foreach ($menus as $val) {
        foreach($val["child"] as $val2) {
            $name = explode("_",$val2["name"]);
            $href = str_replace('_', '/', $val2['name']);
            if(count($name) ==1) continue;
            Route::any($href, 'Api\\'.$name[0].'Controller@'.$name[1].'');
        }
    }
    /**
     * 忽略模块
     */
    $menus = \App\Http\Controllers\AuthController::$super;
    foreach ($menus as $val) {
        $name = explode("_",$val);
        $href = str_replace('_', '/', $val);
        if(count($name) ==1) continue;
        Route::any($href, 'Api\\'.$name[0].'Controller@'.$name[1].'');
    }


});